from rest_framework.viewsets import ModelViewSet
from rest_framework.permissions import IsAdminUser
from django.contrib.auth.models import Group
from rest_framework.response import Response

from meiduo_admin.utils import PageNum
from users.models import User
from meiduo_admin.serializers.admins import AdminsSerializer
from meiduo_admin.serializers.groups import GroupSerializer


class AdminsView(ModelViewSet):
    queryset = User.objects.filter(is_staff=True)
    permission_classes = [IsAdminUser]
    pagination_class = PageNum
    serializer_class = AdminsSerializer

    def simple(self, request):
        data = Group.objects.all()
        ser = GroupSerializer(data, many=True)
        return Response(ser.data)
